#include "helper/sqlite/AutoDBDecorator.h"

#include <cassert>
//#include <iostream>

#include "helper/sqlite/Statement.h"

namespace helper {
namespace sqlite {

AutoDBDecorator::AutoDBDecorator(IDB & db)
: IDB(db.url())
, _db(db) 
{
  //std::cout << "call auto db open" << _db.url()  << std::endl;
  assert(!_db.open());
}

AutoDBDecorator::~AutoDBDecorator() {
  //std::cout << "call auto db close" << _db.url()  << std::endl;
  assert(!_db.close());
}

//helper::resource::Reopenable 
std::error_code AutoDBDecorator::open() {
  return _db.open();
}
std::error_code AutoDBDecorator::close()  {
  return _db.close();
}
bool AutoDBDecorator::isOpened() const  {
  return _db.isOpened();
}

std::error_code AutoDBDecorator::_open()  {
  return std::error_code();
}
std::error_code AutoDBDecorator::_close() {
  return std::error_code();
}

bool AutoDBDecorator::exists() const {
  return _db.exists();
}
std::error_code AutoDBDecorator::destroy() {
  return _db.destroy();
}

std::optional<Statement> AutoDBDecorator::createStatement(const std::string & sql, std::error_code & ec) const {
  return _db.createStatement(sql, ec);
}

const std::string & AutoDBDecorator::url() const {
  return _db.url();
}

void * AutoDBDecorator::raw_handler() const {
  return _db.raw_handler();
}

}//namespace sqlite
}//namespace helper
